#include "ConvertUtil.h"
#include <stdio.h>
#include <malloc.h>
#include <vec.h>
#include <string>

using namespace std;

string model;

void conversionFromObj( Edge** edgeList, Vert** vertList, int* edgeCount, int* vertCount )
{
	char* cstr = new char[model.length() + 1];
	strcpy(cstr, model.c_str());

	FILE* fptr = fopen(cstr, "rt");

	fscanf(fptr, "vc %d ec %d\n", vertCount, edgeCount);

	*vertList = (Vert*)malloc(*vertCount * sizeof(Vert));
	*edgeList = (Edge*)malloc(*edgeCount * sizeof(Edge));

	fscanf(fptr, "\n");

	for (int i=0; i<(*vertCount); i++)
	{
		double x, y;
		fscanf(fptr, "v %lf %lf\n", &x, &y);

		(*vertList)[i].x = x;
		(*vertList)[i].y = y;
	}

	fscanf(fptr, "\n");

	for (int i=0; i<(*edgeCount); i++)
	{
		int ea, eb;

		fscanf(fptr, "e %d %d\n", &ea, &eb);

		(*edgeList)[i].a = ea - 1;
		(*edgeList)[i].b = eb - 1;
	}

	fclose(fptr);

	for (int i=0; i<(*edgeCount); i++)
	{
		int ia = (*edgeList)[i].a;
		int ib = (*edgeList)[i].b;

		(*vertList)[ia].eb = i;
		(*vertList)[ib].ea = i;
	}	
}
